package cn.flying.base.security.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import cn.flying.base.security.domain.SysSeq;

/**
 * @description: 系统序列查询
 * @author: lvyong
 * @date: 2023年06月01日 12:31
 * @version: 1.0
 */
@Mapper
public interface SysSeqMapper {

    /**
     * 查询序列
     *
     * @param seqType
     * @return
     */
    @Select("select id, seq_type, seq_type_desc, seq_head, seq_length, cur_seq_no, min_value, max_value, status, tenant_id, created_by, created_time, updated_by, updated_time, revision from cm_seq where seq_type = #{seqType}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "seqType", column = "seq_type"),
            @Result(property = "seqTypeDesc", column = "seq_type_desc"),
            @Result(property = "seqHead", column = "seq_head"),
            @Result(property = "seqLength", column = "seq_length"),
            @Result(property = "curSeqNo", column = "cur_seq_no"),
            @Result(property = "minValue", column = "min_value"),
            @Result(property = "maxValue", column = "max_value"),
            @Result(property = "status", column = "status"),
            @Result(property = "tenantId", column = "tenant_id"),
            @Result(property = "createdBy", column = "created_by"),
            @Result(property = "createdTime", column = "created_time"),
            @Result(property = "updatedBy", column = "updated_by"),
            @Result(property = "updatedTime", column = "updated_time"),
            @Result(property = "revision", column = "revision"),
    })
    SysSeq getSysSeqNo(String seqType);

    /**
     * 更新序列号
     *
     * @param sysSeq
     */
    @Update("update cm_seq set cur_seq_no =#{curSeqNo}, created_by=#{createdBy}, created_time=#{createdTime}, updated_by=#{updatedBy}, updated_time=#{updatedTime} where id = #{id}")
    void updateSysSeq(SysSeq sysSeq);
}
